//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	MetaFormCtrl.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System.Web.UI.WebControls;

namespace Smart.Common.Forms
{
	/// <summary>
	/// Form control metadata
	/// </summary>
	public class MetaFormCtrl
	{
		/// <summary>
		/// Parent control
		/// </summary>
		public MetaFormCtrl Parent { get; set; }

		/// <summary>
		/// Control title
		/// </summary>
		public string Title { get; set; }

		/// <summary>
		/// Control name
		/// </summary>
		public string Name { get; set; }

		/// <summary>
		/// Control visibility flag
		/// </summary>
		public bool Visible { get; set; }

		/// <summary>
		/// Control enabled flag
		/// </summary>
		public bool Enabled { get; set; }

		/// <summary>
		/// Control read only flag
		/// </summary>
		public bool ReadOnly { get; set; }

		/// <summary>
		/// Control width (or Empty if not defined)
		/// </summary>
		public Unit Width { get; set; }

		/// <summary>
		/// Control height (or Empty if not defined)
		/// </summary>
		public Unit Height { get; set; }

		/// <summary>
		/// Underlying control
		/// </summary>
		public object Control { get; set; }

		/// <summary>
		/// Form control metadata
		/// </summary>
		public MetaFormCtrl(string title, string name)
		{
			Title = title;
			Name = name;

			Enabled = true;
			Visible = true;
			ReadOnly = false;

			if (Title.IsLocalizationKey())
				Title = Title.Localized();
		}

		/// <summary>
		/// Fill control visibility
		/// </summary>
		public virtual void EnsureVisible(bool visible)
		{
			Visible = visible;
		}
	}
}